package org.je.database.impl;

import org.je.ufo.Loop;

/**
 * @author fanyifeng
 */
public class ExecutorGroup
{
	private final Loop			loop;
	private final SqlExecutor[]	exes;
	public final String			id;

	public ExecutorGroup(DataSource ds) {
		if (ds == null) {
			throw new NullPointerException("datasource-is-null");
		}
		id = ds.id;
		exes = new SqlExecutor[ds.connectionCount];
		loop = new Loop(ds.connectionCount);
		for (int i = 0; i < exes.length; ++i) {
			exes[i] = new SqlExecutor(new DBConnection(ds));
		}
	}

	public SqlExecutor getExecutor() {
		return exes[loop.index()];
	}
}
